<template>
  <div class="my_inf">
    <div class="inf_left">
      <div class="inf_photo">
        <img src="../../assets/img/logo.png" alt="" />
        <span>{{ expertInf.e_name }}</span>
      </div>
      <ul class="clear">
        <li>
          部门：<span>{{ expertInf.e_department }}</span>
        </li>
        <li>
          工号：<span>{{ expertInf.e_schoolId }}</span>
        </li>
        <li>
          职务：<span>{{ expertInf.e_post }}</span>
        </li>
        <li>
          地址：<span>{{ expertInf.e_site }}</span>
        </li>
        <li>
          电话：<span>{{ expertInf.e_phone }}</span>
        </li>
        <li>
          邮箱：<span>{{ expertInf.e_eMail }}</span>
        </li>
      </ul>
      <div class="inf_btn">
        <el-button size="small" type="primary" @click="openamendInf()" round
          >修改信息</el-button
        >
        <el-button size="small" type="success" @click="end()" round
          >退出登录</el-button
        >
      </div>
    </div>
    <div class="inf_right">
      <div>
        <h3>审批项目</h3>
        <el-collapse>
          <el-collapse-item
            v-for="(data, i) in project"
            :key="data.id"
            :title="data.p_title"
            :name="i"
          >
            <div>
              {{ data.p_synopsis }}
            </div>
            <el-button
              class="downBtn"
              size="small"
              type="primary"
              round
              v-if="data.p_type == 2"
              ><a class="downBtna">已完结</a></el-button
            >
            <el-button
              class="downBtn"
              size="small"
              type="success"
              round
              v-if="data.p_type == 1"
              ><a class="downBtna">进行中</a></el-button
            >
            <el-button
              class="downBtn"
              size="small"
              type="danger"
              round
              v-if="data.p_type == 0"
              ><a class="downBtna">待申请</a></el-button
            >
            <el-button
              class="downBtn"
              size="small"
              type="danger"
              round
              v-if="data.p_type == 11"
              ><a class="downBtna">待审批</a></el-button
            >
          </el-collapse-item>
        </el-collapse>
      </div>
    </div>
    <el-dialog title="修改信息" :visible.sync="dialogFormVisible">
      <ul class="tc_mes">
        <li>电话：<input type="text" v-model="expertInf.e_phone" /></li>
        <li>邮件：<input type="text" v-model="expertInf.e_eMail" /></li>
      </ul>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelamendInf">取 消</el-button>
        <el-button type="primary" @click="amendInf">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      expert_id: "",
      expertInf: {},
      project: [],
      dialogFormVisible: false,
    };
  },
  mounted() {
    var token = localStorage.getItem("token");
    this.expert_id = token.substring(1, token.length - 1).split("#")[1] * 1;
    this.getExpertData();
  },
  methods: {
    getExpertData() {
      axios
        .post(`http://localhost:3000/expert/MyMes`, {
          e_id: this.expert_id,
        })
        .then((ret) => {
          this.project = ret.data.expertMes.project;
          this.expertInf = ret.data.expertMes.mes;
        });
    },
    cancelamendInf() {
      this.dialogFormVisible = false;
    },
    openamendInf() {
      this.dialogFormVisible = true;
    },
    // 修改信息
    amendInf() {
      axios
        .post(`http://localhost:3000/updateExpert`, {
          expertData: this.expertInf,
        })
        .then((ret) => {
          if (ret.data.code == 1) {
            this.$message({
              showClose: true,
              message: "修改成功",
              type: "success",
            });
            this.cancelamendInf();
          }
        });
    },
    end() {
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
  },
};
</script>

<style scoped>
.my_inf {
  display: flex;
  justify-content: space-around;
  padding: 10px 20px;
}
.inf_left {
  width: 300px;
  height: 700px;
  position: sticky;
  top: 10px;
  padding: 0px 10px;
}
.inf_left,
.inf_right > div {
  border-radius: 20px;
  border: 1px solid #ddd;
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  border-left: 2px solid rgba(255, 255, 255, 0.5);
  border-top: 2px solid rgba(255, 255, 255, 0.5);
}
.inf_photo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 20px auto;
  font-size: 18px;
  font-weight: 700;
  color: #303133;
}
.inf_photo > img {
  width: 50px;
  height: 50px;
  overflow: hidden;
  border-radius: 50%;
  border: 1px solid #ddd;
  border-left: 2px solid rgba(255, 255, 255, 0.5);
  border-top: 2px solid rgba(255, 255, 255, 0.5);
}
.inf_left > ul {
  border-top: 2px solid #606266;
  margin-bottom: 200px;
}
.inf_left > ul > li {
  font-size: 16px;
  color: #606266;
  margin: 20px 10px;
}
.inf_btn {
  margin: 20px 10px;
}
.inf_right {
  width: 70%;
}
.inf_right > div {
  margin-bottom: 20px;
  box-sizing: border-box;
  padding: 10px 20px;
}
.inf_right > div > h3 {
  width: 100px;
  height: 40px;
  font: 18px/40px "";
  font-weight: 700;
  color: #303133;
  text-align: center;
  border-bottom: 2px solid #606266;
}
.awards_list {
  display: flex;
  flex-wrap: wrap;
}
.awards_list li {
  width: 35%;
  margin: 20px;
  padding: 10px;
  color: white;
  background-color: #409eff;
  border-radius: 20px;
}
.team_card {
  border-radius: 10px;
  padding: 20px;
  margin: 10px;
  color: white;
  background-color: #409eff;
}
.team_card img {
  background-color: #fff;
}
.team_card > h4 {
  height: 24px;
  font-weight: 700;
  font: 18px/24px "";
}
.team_card > div {
  margin-top: 5px;
  height: 60px;
  display: flex;
  align-items: center;
}
.team_card > div > span {
  font-size: 18px;
  display: inline-block;
}
.team_card > div > div {
  display: inline-block;
  margin: 0 20px;
}
.delbtn {
  display: inline-block;
  width: 270px;
}
.downBtn {
  margin: 10px;
  float: right;
}
.projectBox {
  display: flex;
  width: 100%;
  margin: 10px auto;
}
.tc_mes {
  width: 80%;
  margin-left: 50px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.tc_mes > li {
  width: 33%;
  font-size: 14px;
  color: #606266;
  letter-spacing: 1px;
  margin-bottom: 5px;
}
img {
  display: block;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid #ddd;
}
</style>
